package com.koron.tool.entity;

import java.io.Serializable;
import java.util.*;

/**
 * Created by zhenbiao on 2016/11/12.
 */
public class Table implements Serializable {

    //所有的列
    private Map<String,Column>columnMap = new LinkedHashMap<>();

    //表名
    private String tableName;

    //表的别名
    private String tableAlias;

    //表的第二个别名
    private String secondTableAlias;

    private List<ForeignKey> foreignKeys = new ArrayList<>();







    //外键
    private Map<String,Table>foreignKeyMap = new HashMap<>();

    public void addColumn(Column column){
        if(column == null){
            return;
        }
        columnMap.put(column.getColumnName(),column);
    }



    public Map<String, Column> getColumnMap() {
        return columnMap;
    }

    public void setColumnMap(Map<String, Column> columnMap) {
        this.columnMap = columnMap;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public Map<String, Table> getForeignKeyMap() {
        return foreignKeyMap;
    }

    public void setForeignKeyMap(Map<String, Table> foreignKeyMap) {
        this.foreignKeyMap = foreignKeyMap;
    }

    public Column getColumnByColumnName(String columnName){
        return columnMap.get(columnName);
    }

    public int getColumnCount(){
        return columnMap.size();
    }

    public List<Column> getColumns(){
        return new ArrayList<>(columnMap.values());
    }

    public List<ForeignKey> getForeignKeys() {
        return foreignKeys;
    }

    public void setForeignKeys(List<ForeignKey> foreignKeys) {
        this.foreignKeys = foreignKeys;
    }

    public void addForeignKey(ForeignKey foreignKey){
        foreignKeys.add(foreignKey);
    }

    public String getTableAlias() {
        return tableAlias;
    }

    public void setTableAlias(String tableAlias) {
        this.tableAlias = tableAlias;
    }

    public String getSecondTableAlias() {
        return secondTableAlias;
    }

    public void setSecondTableAlias(String secondTableAlias) {
        this.secondTableAlias = secondTableAlias;
    }
}
